#ifndef pktoon_Semaphore_h
#define pktoon_Semaphore_h

#ifndef WIN32
# include <pthread.h>
# include <semaphore.h>
#endif
#include "ThreadConsts.h"
#include "Guard.h"

namespace catan
{
	class Semaphore
	{
	public:
		Semaphore(int initValue = 0);
		~Semaphore();

		LockState::Enum Acquire(long timeout = -1);		// timeout is in milliseconds

		LockState::Enum TryAcquire();

		void Release();

		typedef Guard<Semaphore> Guard;
	private:
#ifdef WIN32
		void* mSem;
#else
		sem_t mSem;
#endif
	};
}

#endif
